home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / endo / event.c < prev    next >
C/C++ Source or Header  |  1995-05-12  |  10KB  |  377 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. #include "x.h"
  17.  
  18. image_data_t rubber_data;
  19. int p_inc, q_inc;
  20.  
  21. copy_periods()
  22. {
  23.     static int i, j, copyrows;
  24.  
  25.     if ((2*point.y) > height)
  26.         copyrows = height - (point.y + 1);
  27.     else
  28.         copyrows = point.y - 1;
  29.     if (lyap)
  30.         for (i = 0; i<copyrows; i++) {
  31.             for (j = 0; j<width; j++) {
  32.                 periods[frame][(((copyrows+point.y-1)-i)*width)+j] = 
  33.                         periods[frame][((point.y-copyrows+i)*width)+j];
  34.                 indices[frame][(((copyrows+point.y-1)-i)*width)+j] =
  35.                         indices[frame][((point.y-copyrows+i)*width)+j];
  36.             }
  37.         }
  38.     else
  39.         for (i = 0; i<copyrows; i++) {
  40.             for (j = 0; j<width; j++) {
  41.                 periods[frame][(((copyrows+point.y)-i)*width)-(j+1)] = 
  42.                         periods[frame][((point.y-copyrows+i)*width)+j];
  43.                 indices[frame][(((copyrows+point.y)-i)*width)-(j+1)] =
  44.                         indices[frame][((point.y-copyrows+i)*width)+j];
  45.             }
  46.         }
  47.     perind[frame] += copyrows * width;
  48.     point.y += copyrows;
  49.     y = ((point.y-1) * y_inc) + min_y;
  50.     AllFlushBuffer(); redraw(indices[frame], perind[frame], 1);
  51. }
  52.  
  53. increment(method)
  54. int method;
  55. {
  56.     extern void save_to_file();
  57.     extern double drand48();
  58.     extern int symmetric[], found_arc, idown, demo;
  59.     static int tlyap;
  60.  
  61.     if ((!method) || (method == 4)) {    /* compute row by row like normal */
  62.         x += x_inc;             /* or refined mesh (method = 4) */
  63.         point.x += p_inc;
  64.         if ((x >= max_x) || (point.x >= width) || 
  65.            (thermometer && (point.x >= width - THERMWIDTH))) {
  66.             x = min_x;
  67.             y += y_inc;
  68.             point.x = 0;
  69.             point.y += q_inc;
  70.             if (clearflag)
  71.                 Clear(trajec);
  72.             if (randinit && lyap) {
  73.                 tlyap = lyap;
  74.                 lyap = 0; setparams(mapindex);
  75.                 start_x = (drand48() * x_range) + min_x;
  76.                 start_y = (drand48() * y_range) + min_y;
  77.                 lyap = tlyap; setparams(mapindex);
  78.             }
  79.             if (symmetric[mapindex] && (y>0) && ((y-y_inc) <= 0))
  80.                 copy_periods();
  81.         }
  82.         if ((y >= max_y) || (point.y >= height)) {
  83.             AllFlushBuffer();
  84.             if ((found_arc) && (critical))
  85.                 find_arcs(A0, A1);
  86.             if (method == 4) {
  87.                 x = min_x; y = min_y;
  88.                 point.x = point.y = 0;
  89.                 x_inc *= 0.5; y_inc *= 0.5; 
  90.                 p_inc *= 0.5; q_inc *= 0.5;
  91.                 if (((numrows *= 2) > width) && ((row *=2) > height)) {
  92.                     run = 0;
  93.                     if (histogram)
  94.                         FlushBuffer(dpy,trajec,pixtra,Data_GC,&Histog,
  95.                                         0,numcolors);
  96.                     if (!idown)
  97.                         Show_Info();
  98.                     if (demo) {
  99.                         recalc();
  100.                         redraw(indices[frame], perind[frame], 1);
  101.                     }
  102.                     if (savefile == 1)
  103.                         save_to_file(pixmap, width, height);
  104.                     if (savefile == 2)
  105.                         save_to_file(pixtra,trawidth,traheight);
  106.                 }
  107.             }
  108.             else {
  109.                 run = 0;
  110.                 if (histogram)
  111.                     FlushBuffer(dpy,trajec,pixtra,Data_GC,&Histog,0,numcolors);
  112.                 if (!idown)
  113.                     Show_Info();
  114.                 if (savefile == 1)
  115.                     save_to_file(pixmap, width, height);
  116.                 if (savefile == 2)
  117.                     save_to_file(pixtra,trawidth,traheight);
  118.             }
  119.         }
  120.     }
  121.     else if (method == 1) {        /* just compute the diagonal */
  122.         x += x_inc;
  123.         y = x;
  124.         point.x++;
  125.         point.y = (y - min_y) / y_inc;
  126.         if ((x >= max_x) || (point.x >= width) || 
  127.             (thermometer && (point.x >= width - THERMWIDTH)) ||
  128.             (y >= max_y) || (point.y >= height)) {
  129.             AllFlushBuffer();
  130.             if ((found_arc) && (critical))
  131.                 find_arcs(A0, A1);
  132.             run = 0;
  133.             if (histogram)
  134.                 FlushBuffer(dpy,trajec,pixtra,Data_GC,&Histog,0,numcolors);
  135.             if (!idown)
  136.                 Show_Info();
  137.             if (savefile == 1)
  138.                 save_to_file(pixmap, width, height);
  139.             if (savefile == 2)
  140.                 save_to_file(pixtra,trawidth,traheight);
  141.         }
  142.     }
  143.     else if (method == 2) {        /* compute a row then a column */
  144.         if (row) {
  145.             x += x_inc;
  146.             point.x++;
  147.         }
  148.         else {
  149.             y += y_inc;
  150.             point.y++;
  151.         }
  152.         if ((x >= max_x-(numrows*x_inc))||(point.x >= width-numrows) ||
  153.            (thermometer && (point.x >= width - THERMWIDTH - numrows))) {
  154.             row = 0;
  155.             y += y_inc;
  156.             point.y++;
  157.             x -= x_inc;
  158.             point.x--;
  159.             if (clearflag)
  160.                 Clear(trajec);
  161.             if (randinit && lyap) {
  162.                 tlyap = lyap;
  163.                 lyap = 0; setparams(mapindex);
  164.                 start_x = (drand48() * x_range) + min_x;
  165.                 start_y = (drand48() * y_range) + min_y;
  166.                 lyap = tlyap; setparams(mapindex);
  167.             }
  168.         }
  169.         if ((y >= max_y) || (point.y >= height)) {
  170.             row = 1;
  171.             x = min_x;
  172.             point.x = 0;
  173.             y = min_y + (numrows * y_inc);
  174.             point.y = numrows++;
  175.             if ((y >= max_y) || (point.y >= height)) {
  176.                 AllFlushBuffer();
  177.                 if ((found_arc) && (critical))
  178.                     find_arcs(A0, A1);
  179.                 run = 0;
  180.                 if (histogram)
  181.                     FlushBuffer(dpy,trajec,pixtra,Data_GC,&Histog,0,numcolors);
  182.                 if (!idown)
  183.                     Show_Info();
  184.                 if (savefile == 1)
  185.                     save_to_file(pixmap, width, height);
  186.                 if (savefile == 2)
  187.                     save_to_file(pixtra,trawidth,traheight);
  188.             }
  189.         }
  190.     }
  191.     else if (method == 3) {        /* compute a column then a row */
  192.         if (row) {
  193.             y += y_inc;
  194.             point.y++;
  195.         }
  196.         else {
  197.             x += x_inc;
  198.             point.x++;
  199.         }
  200.         if ((y >= max_y-(numrows*y_inc))||(point.y >= height-numrows)) {
  201.             row = 0;
  202.             x += x_inc;
  203.             point.x++;
  204.             y -= y_inc;
  205.             point.y--;
  206.             if ((y < min_y) || (point.y < 0)) {
  207.                 AllFlushBuffer();
  208.                 if ((found_arc) && (critical))
  209.                     find_arcs(A0, A1);
  210.                 run = 0;
  211.                 if (histogram)
  212.                     FlushBuffer(dpy,trajec,pixtra,Data_GC,&Histog,0,numcolors);
  213.                 if (!idown)
  214.                     Show_Info();
  215.                 if (savefile == 1)
  216.                     save_to_file(pixmap, width, height);
  217.                 if (savefile == 2)
  218.                     save_to_file(pixtra,trawidth,traheight);
  219.             }
  220.             if (clearflag)
  221.                 Clear(trajec);
  222.             if (randinit && lyap) {
  223.                 tlyap = lyap;
  224.                 lyap = 0; setparams(mapindex);
  225.                 start_x = (drand48() * x_range) + min_x;
  226.                 start_y = (drand48() * y_range) + min_y;
  227.                 lyap = tlyap; setparams(mapindex);
  228.             }
  229.         }
  230.         if ((x >= max_x) || (point.x >= width) ||
  231.            (thermometer && (point.x >= width - THERMWIDTH))) {
  232.             row = 1;
  233.             y = min_y;
  234.             point.y = 0;
  235.             x = min_x + (numrows * x_inc);
  236.             point.x = numrows++;
  237.             if ((x >= max_x) || (point.x >= width) ||
  238.                (thermometer && (point.x >= width - THERMWIDTH))) {
  239.                 AllFlushBuffer();
  240.                 if ((found_arc) && (critical))
  241.                     find_arcs(A0, A1);
  242.                 run = 0;
  243.                 if (histogram)
  244.                     FlushBuffer(dpy,trajec,pixtra,Data_GC,&Histog,0,numcolors);
  245.                 if (!idown)
  246.                     Show_Info();
  247.                 if (savefile == 1)
  248.                     save_to_file(pixmap, width, height);
  249.                 if (savefile == 2)
  250.                     save_to_file(pixtra,trawidth,traheight);
  251.             }
  252.         }
  253.     }
  254.     else
  255.         usage();
  256. }
  257.  
  258. main_event()
  259. {
  260.     static int n, p_exposed, c_exp;
  261.     static int exposed,c_exposed,t_exposed,l_exposed,i_exposed,h_exposed,b_exp;
  262.     XEvent event,c_event,a_event,t_event,l_event,i_event,h_event,p_event,b_eve;
  263.     XEvent c_eve;
  264.     extern int Qflag;
  265.     extern void Getkey();
  266.  
  267.     if (run) {
  268.         compendo();
  269.         increment(Qflag);
  270.     }
  271.     exposed = t_exposed = l_exposed = i_exposed = h_exposed = c_exposed = 0;
  272.     p_exposed = b_exp = c_exp = 0;
  273.     n = XEventsQueued(dpy, QueuedAfterFlush);
  274.     while (n--) {
  275.         XNextEvent(dpy, &event);
  276.         switch(event.type) 
  277.         {
  278.         case KeyPress:
  279.             Getkey(&event);
  280.             break;
  281.         case Expose:
  282.             if (event.xexpose.window == canvas) {
  283.                 exposed = 1;
  284.                 a_event = event;
  285.             }
  286.             else if (event.xexpose.window == trajec) {
  287.                 t_exposed = 1;
  288.                 t_event = event;
  289.             }
  290.             else if (event.xexpose.window == crijec) {
  291.                 c_exposed = 1;
  292.                 c_event = event;
  293.             }
  294.             else if (event.xexpose.window == prejec) {
  295.                 p_exposed = 1;
  296.                 p_event = event;
  297.             }
  298.             else if (event.xexpose.window == lyajec) {
  299.                 l_exposed = 1;
  300.                 l_event = event;
  301.             }
  302.             else if (event.xexpose.window == info) {
  303.                 i_exposed = 1;
  304.                 i_event = event;
  305.             }
  306.             else if (event.xexpose.window == help) {
  307.                 h_exposed = 1;
  308.                 h_event = event;
  309.             }
  310.             else if (event.xexpose.window == hisbar) {
  311.                 b_exp = 1;
  312.                 b_eve = event;
  313.             }
  314.             else if (event.xexpose.window == colwin) {
  315.                 c_exp = 1;
  316.                 c_eve = event;
  317.             }
  318.             break;
  319.         case ConfigureNotify:
  320.             resize(event.xconfigure.window);
  321.             break;
  322.         case ButtonPress:
  323.             if ((event.xbutton.window == canvas) ||
  324.                 (event.xbutton.window == trajec) ||
  325.                 (event.xbutton.window == crijec) ||
  326.                 (event.xbutton.window == lyajec) ||
  327.                 (event.xbutton.window == prejec))
  328.                 StartRubberBand(event.xbutton.window, &rubber_data, &event);
  329.             if (event.xbutton.window == colwin)
  330.                 StartSegments(event.xbutton.window, &rubber_data, &event);
  331.             break;
  332.         case MotionNotify:
  333.             if ((event.xmotion.window == canvas) ||
  334.                 (event.xmotion.window == trajec) ||
  335.                 (event.xmotion.window == crijec) ||
  336.                 (event.xmotion.window == lyajec) ||
  337.                 (event.xmotion.window == prejec))
  338.                 TrackRubberBand(event.xmotion.window, &rubber_data, &event);
  339.             if (event.xmotion.window == colwin)
  340.                 TrackSegments(event.xmotion.window, &rubber_data, &event);
  341.             break;
  342.         case ButtonRelease:
  343.             if ((event.xbutton.window == canvas) ||
  344.                 (event.xbutton.window == trajec) ||
  345.                 (event.xbutton.window == crijec) ||
  346.                 (event.xbutton.window == lyajec) ||
  347.                 (event.xbutton.window == prejec))
  348.                 EndRubberBand(event.xbutton.window, &rubber_data, &event);
  349.             if (event.xmotion.window == colwin)
  350.                 EndSegments(event.xbutton.window, &rubber_data, &event);
  351.             break;
  352.         case FocusIn:
  353.             SetFocus(event.xfocus.window);
  354.             break;
  355.         }
  356.     }
  357.     if (exposed)
  358.         redisplay(&a_event);
  359.     if (t_exposed)
  360.         redisplay(&t_event);
  361.     if (c_exposed)
  362.         redisplay(&c_event);
  363.     if (p_exposed)
  364.         redisplay(&p_event);
  365.     if (l_exposed)
  366.         redisplay(&l_event);
  367.     if (b_exp)
  368.         redisplay(&b_eve);
  369.     if (c_exp)
  370.         redisplay(&c_eve);
  371.     if (h_exposed)
  372.         redisplay(&h_event);
  373.     if (i_exposed)
  374.         redisplay(&i_event);
  375. }
  376.  
  377.